﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Brain
{
    public static class RandomUtil
    {
        public static Random Random = new Random();

        public static Vector3 RandomVector3(Vector3 min, Vector3 max, float precision)
        {
            return new Vector3(RandomUtil.Next(min.X, max.X, precision),
                                RandomUtil.Next(min.Y, max.Y, precision),
                                RandomUtil.Next(min.Z, max.Z, precision));
        }


        public static Vector2 RandomPointInRectangle(Rectangle rect)
        {
            return new Vector2(Next(rect.X, rect.X + rect.Width),
                Next(rect.Y, rect.Y + rect.Height));
        }

        public static Vector3 RandomPointInArea(Vector3 min, Vector3 max)
        {
            return new Vector3(Next(min.X, max.X, 100),
                Next(min.Y, max.Y, 100),
                Next(min.Z, max.Z, 100));
        }

        /// <summary>
        /// Returns a Random Float Number within a specified range
        /// </summary>
        /// <param name="MinValue">Minimum value the random can take</param>
        /// <param name="MaxValue">Maximum value the random can take</param>
        /// <param name="Precision">The precision. Usually 100 or 1000 is good enough.</param>
        /// <returns></returns>
        public static float Next(float MinValue, float MaxValue, float Precision)
        {
            int minValue = (int)(MinValue * Precision);
            int maxValue = (int)(MaxValue * Precision);
            return Random.Next(minValue, maxValue) / Precision;
        }

        /// <summary>
        /// Returns a non-negative random number
        /// </summary>
        /// <returns></returns>
        public static int Next()
        {
            return Random.Next();
        }

        /// <summary>
        /// Returns a non-negative random number less than the specified maximum
        /// </summary>
        /// <param name="MaxValue">Maximum value</param>
        /// <returns></returns>
        public static int Next(int MaxValue)
        {
            return Random.Next(MaxValue);
        }

        /// <summary>
        /// Returns a Random Number within a specified range
        /// </summary>
        /// <param name="MinValue">Minimum value(included)</param>
        /// <param name="MaxValue">Maximum value(excluded)</param>
        /// <returns></returns>
        public static int Next(int MinValue, int MaxValue)
        {
            return Random.Next(MinValue, MaxValue);
        }

        /// <summary>
        /// Randomizer used for Probability (1 to 100%)
        /// </summary>
        /// <param name="Percentage"></param>
        /// <returns></returns>
        public static bool Probability(int Percentage)
        {
            int random = Random.Next(0, 100);
            return (Percentage >= random);
        }
    }
}
